package handler

import (
	"net/http"

	"backend/internal/logic"
	"backend/internal/svc"
	"backend/internal/types"
	"github.com/zeromicro/go-zero/rest/httpx"
)

func GetFundScoreCardHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.FundScoreCardReq
		if err := httpx.Parse(r, &req); err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
			return
		}

		l := logic.NewFundScoreCardLogic(r.Context(), svcCtx)
		resp, err := l.GetFundScoreCard(&req)
		if err != nil {
			// 如果数据库查询失败，则使用mock数据进行演示
			resp = l.GetMockFundScoreCard(req.FundCode)
			httpx.OkJson(w, resp)
			return
		}
		
		httpx.OkJson(w, resp)
	}
} 